$(function () {

    if ($('#goods_id').length) {
        ITEM_ID = $('#goods_id').val();
    }
    else {
        ITEM_ID = '';
    }

    if (ATTACH_ACCESS_KEY != '') {
        var upload_url = G_BASE_URL + '/admin/goods_ajax/upload/goods_id-'+ITEM_ID+'__attach_access_key-' + ATTACH_ACCESS_KEY;
        var fileupload = new FileUpload('file', '.goods_photos_uploads', '.photos-container', upload_url, {
            'editor': editor,
            'insertBtn': false,
            'coverBtn': true
        });
    }

    if (ITEM_ID && ATTACH_ACCESS_KEY != '') {
        if ($(".aw-upload-box .upload-list").length) {
            $.post(G_BASE_URL + '/admin/goods_ajax/goods_attach_edit_list/', PUBLISH_TYPE + '_id=' + ITEM_ID, function (data) {
                if (data['err']) {
                    return false;
                } else {
                    if (data['rsm']['attachs']) {
                        $.each(data['rsm']['attachs'], function (i, v) {
                            fileupload.setFileList(v);
                        });
                    }
                }
            }, 'json');
        }
    }

    //提交表单
    $("#goodsPost").click(function () {
        UE.getEditor('editor').getAllHtml();

        AWS.ajax_post($('#settings_form'));

    });


//    型号
    $("#goodsStyleAdd").click(function () {

        var tpl = $("#goodStyleCloneTpl").clone();
        $("#goodsModelTable").append(tpl);
    });

//    颜色选择
    $("#goods_style").on("change",'.js-goods-color-choose',function() {
        var name = $(this).find('option:selected').data('name');
        if(name){
          $(this).siblings('input[name=goods_color_name]').val(name);
        }

    });

//    提交保存
    $("#goods_style").on("click",'.js-goods-style-submit',function(){

        AWS.ajax_post($(this).parents(".js-goods-style-form"));
    });

});